import socket as sk


class Receiver:
    data: list
    last_tick: float
    base: float

    def __init__(self, base: float):
        self.data = []
        self.last_tick = 0
        self.base = base

    def add_tick(self, tick: float):
        if self.last_tick == 0:
            # 第一次数据 不需要求解差值
            self.last_tick = tick
        else:
            # 求解差值 装入数组
            offset: float = tick - self.last_tick
            self.data.append(offset * self.base)
            self.last_tick = tick

    def answer(self):
        # ans = "["
        # for i in range(len(self.data)):
        #     ans = ans + str(self.data[i])
        #     if i != len(self.data) - 1:
        #         ans = ans + ", "
        # ans = ans + "]"
        return self.data

    def __len__(self):
        return len(self.data)
